﻿
$(function () {
    $('#Email').mailAutoComplete();
    $('.emailist').css('margin-left', 100);
    $('#Account').focus();
    $("#valiCode").on("click", function () {
        $(this).attr("src", "GetValidateCode?rd=" + Math.random());
    });
    if (!isPC()) {
        $('#layer-bg').remove();
    } else {
        setInterval(function () {
            l++;
            if (l > 3) {
                l = 1;
            }
            $("#layer-bg").animate({ opacity: 'toggle' }, "slow", null, function () {
                $("#layer-bg").attr("src", '/Content/Images/body-bg' + l + '.jpg');
                $("#layer-bg").animate({ opacity: 'toggle' }, "slow");
            });
        }, 5000);
    }
});
var l = 1;
var i = 3;
var j = 20;
function Success(obj) {
    if (obj.State == 4) {
        var index = layer.open({
            type: 1,
            title: '帐号激活提示',
            closeBtn: 1, //0不显示关闭按钮
            shift: 2,
            content: '<div id="dv-active" style="width:340px;height:70px;margin:10px;">'
            + '<label>激活码已经发送到了您的邮箱，请输入激活码：</label>'
            + '<input id="activeCode" type="text" style="margin-top:10px; padding:10px;width:280px!important;border:1px solid #7d8272;font-size:14px;" /></div>',
            btn: ['激活', '重新获取激活码'],
            success: function () {
                $('#activeCode').focus();
                $('.layui-layer-btn1').text('20秒后可重新获取');
                var loop = setInterval(function () {
                    if (j > 0) {
                        $('.layui-layer-btn1').css({ 'cursor': 'none', 'background': '#92B8B1', 'color': '#000' }).text((j - 1) + '秒后可重新获取');
                        j--;
                    } else {
                        clearInterval(loop);
                        j = 20;
                        $('.layui-layer-btn1').css({ 'cursor': 'pointer', 'background': '#0daf22', 'color': '#fff' }).text('重新获取激活码');
                    }
                }, 1000);
            },
            yes: function () {
                if (!$.trim($('#activeCode').val())) {
                    $('#activeCode').focus();
                    return false;
                }
                $.post('/account/active', { account: $('#Account').val(), activeCode: $.htmlEncode($('#activeCode').val()), token: obj.Data.token2 }, function (o) {
                    if (o.State == 1) {
                        layer.close(index);
                        $("#btnReg").attr("disabled", "disabled");
                        $('.dv-block').last().html('<div id="dvmsg" class="reg-succ-tip">注册成功！页面将在<span id="spmsg" class="red">3</span>秒内跳转……<br />如没有跳转，请单击<a class="blod red underline" href="' + o.Url + '">这里</a></div>');
                        var loop = setInterval(function () {
                            if (i > 0) {
                                $("#spmsg").html(i - 1);
                                i--;
                            } else {
                                clearInterval(loop);
                                location.href = o.Url;
                            }
                        }, 1000);
                    } else {
                        layerAlert('你输入的激活码有误，请重新输入！', function () { $('#activeCode').focus(); });
                    }
                });
            },
            btn2: function () {
                if ($('.layui-layer-btn1').text() != '重新获取激活码') {
                    return false;
                }
                $.post('/account/sendactivecode', { account: $('#Account').val() }, function (o) {
                    if (o.State == 1) {
                        layerMsg('已重新发送激活码到您的邮箱，请注意查收。', function () { return false; }, null, 5000);
                        $('#activeCode').focus();
                        var loop = setInterval(function () {
                            if (j > 0) {
                                $('.layui-layer-btn1').css({ 'cursor': 'none', 'background': '#92B8B1', 'color': '#000' }).text((j - 1) + '秒后可重新获取');
                                j--;
                            } else {
                                clearInterval(loop);
                                j = 20;
                                $('.layui-layer-btn1').css({ 'cursor': 'pointer', 'background': '#0daf22', 'color': '#fff' }).text('重新获取激活码');
                            }
                        }, 1000);
                    }
                });
                return false;
            },
            cancel: function () {
                layerConfirm('确定取消本次注册吗？', function () {
                    $.post('/account/cancelreg', { account: $('#Account').val(), token: obj.Data.token }, function (o) {
                        if (o.State == 1) {
                            window.location.reload();
                        }
                    })
                });
                return false;
            }
        });
    }
    if (obj.State == 2) {
        $.showAjaxMessage(obj, $("#regErr"), null);
    }
}

function getTime() {
    setInterval(function () {
        var date = new Date();
        var year = date.getFullYear();
        var month = $.fillNumString(date.getMonth() + 1);
        var day = $.fillNumString(date.getDate());
        var hour = $.fillNumString(date.getHours());
        var minute = $.fillNumString(date.getMinutes());
        var second = $.fillNumString(date.getSeconds());
        $("#lbltime").html("当前时间：" + year + "年" + month + "月" + day + "日 "
            + hour + ":" + minute + ":" + second)
    }, 1000);
}

function Fail(obj) {
    $("#regErr").html("*系统错误，暂时无法注册");
}
